clear
clear matrix
clear mata
set more off, perm
set matsize 11000
set maxvar 30000
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/
global output /Users/zachbrown/Projects/PriceTransparency/Output


// open visit dataset
use clean/radiology_visit_3.dta, clear

drop if ym>=ym(2007,1)

// Make (false) treatment indicator
gen post = (ym>=ym(2006,3))
gen web_post = (visit_on_web==1 & post==1)
label var web_post "$\text{OnWeb}\textsubscript{m}\times\text{Post}\textsubscript{t}$"

// Set X controls
global ctr_vars1 = "has_copay has_coin##deduct_type age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"
global ctr_vars2 = "age male i.charlindex zip_mean_income zip_pct_ba i.rural_class i.ym i.std_product_type i.payer_id"


///////////////////////
// Baseline Allowed
///////////////////////

areg ln_amt_allowed web_post $ctr_vars1, absorb(proc_id_radio) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a1

areg ln_amt_allowed web_post $ctr_vars2 if has_deduct==0, absorb(proc_id_radio) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a2

areg ln_amt_allowed web_post $ctr_vars2 if past_deduct==0, absorb(proc_id_radio) vce(cl ym)
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a3

areg ln_amt_allowed web_post $ctr_vars2 if past_deduct==1, absorb(proc_id_radio) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a4

esttab a1 a2 a3 a4 using $output/placebo_regs_a.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(web_post)  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 
	
esttab a1 a2 a3 a4 using $output/placebo_regs_b.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp ar2 N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 



///////////////////////
// Baseline OOP
///////////////////////

areg ln_amt_member_oop web_post $ctr_vars1, absorb(proc_id_radio) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a5

areg ln_amt_member_oop web_post $ctr_vars2 if has_deduct==0, absorb(proc_id_radio) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a6

areg ln_amt_member_oop web_post $ctr_vars2 if past_deduct==0, absorb(proc_id_radio) vce(cl ym)
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a7

areg ln_amt_member_oop web_post $ctr_vars2 if past_deduct==1, absorb(proc_id_radio) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a8

esttab a5 a6 a7 a8 using $output/placebo_regs_c.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(web_post)  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 
	
esttab a5 a6 a7 a8 using $output/placebo_regs_d.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp ar2 N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 


///////////////////////
// Baseline Paid
///////////////////////

areg ln_amt_paid web_post $ctr_vars1, absorb(proc_id_radio) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a9

areg ln_amt_paid web_post $ctr_vars2 if has_deduct==0, absorb(proc_id_radio) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a10

areg ln_amt_paid web_post $ctr_vars2 if past_deduct==0, absorb(proc_id_radio) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a11

areg ln_amt_paid web_post $ctr_vars2 if past_deduct==1, absorb(proc_id_radio) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a12

esttab a9 a10 a11 a12 using $output/placebo_regs_e.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(web_post)  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 
	
esttab a9 a10 a11 a12 using $output/placebo_regs_f.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp ar2 N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 


